import { Route, Redirect } from 'react-router-dom';
import { isAuth } from 'utils';
const AuthRoute = ({ component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) => {
        //判断是否登录
        if (!isAuth()) {
          // 未登录
          return (
            <Redirect
              to={{
                pathname: '/login',
                state: { from: props.location.pathname },
              }}
            />
          );
        }
        //登录
        return <Component />;
      }}
    />
  );
};
export { AuthRoute };
